/*
 * Copyright (c) 2010 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.lgiavedoni.android.franq.service.phone.calendar.dao.imp.webModel;

import java.io.IOException;

import org.lgiavedoni.android.franq.core.calendar.Calendar;

import com.google.api.client.http.HttpTransport;

/**
 * @author Yaniv Inbar
 */
public class CalendarEntry extends Entry implements Calendar {

	public String getEventFeedLink() {
		return Link.find(links, "http://schemas.google.com/gCal/2005#eventFeed");
	}

	@Override
	public CalendarEntry clone() {
		return (CalendarEntry) super.clone();
	}

	@Override
	public CalendarEntry executeInsert(HttpTransport transport, CalendarUrl url) throws IOException {
		return (CalendarEntry) super.executeInsert(transport, url);
	}

	public CalendarEntry executePatchRelativeToOriginal(HttpTransport transport, CalendarEntry original) throws IOException {
		return (CalendarEntry) super.executePatchRelativeToOriginal(transport, original);
	}

	@Override
	public String getTitle() {
		return title;
	}

	@Override
	public String getId() {
		for (Link l : links) {
			if (l.href.contains("calendar/feeds/")) {
				String id = "";
				id = l.href.substring("calendar/feeds/".length() + l.href.indexOf("calendar/feeds/"));
				id = id.substring(0, id.indexOf("/"));
				id = id.replaceAll("%40", "@");
				return id;
			}
		}
		return "UNDEFINED";
	}

	@Override
	public String toString() {
		return title != null ? title : "UNDEFINED";
	}

}
